package servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;
import modelo.bean.Trajeto;

import modelo.bean.Usuario;
import modelo.dao.jpa.JPATrajetoDAO;
import testeMapas.FachadaDirectionsResult;

public class CadastraTrajetoServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String param = request.getParameter("param");
		String start = request.getParameter("start");
		String end = request.getParameter("end");                
                String tempo = request.getParameter("tempo");                        
                String distancia = request.getParameter("distancia");                        
                String coord = request.getParameter("coord");                        
                
	
			System.out.println("Cadastra carona:");
			response.setContentType("text/xml");
			String[] temp = param.split(",");
			for (int i = 0; i < temp.length; i++) {
				//System.out.println("i[" + i + "]: " + temp[i]);
			}
			System.out.println("taaamanaho: " + temp.length);
			Trajeto result = null;
			
			System.out.println("entrada: " + param);
						
                        result = new Trajeto(param, coord, start, end, Integer.parseInt(tempo), Integer.parseInt(distancia));
                                                		                        
                        JPATrajetoDAO dao = new JPATrajetoDAO();                        
                        HttpSession session = request.getSession();
                        Usuario us = (Usuario)session.getAttribute("usuario");                        
                        result.setId_usuario(us);                        
                        dao.insert(result);



	}

}